﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Comod_PriceAdd : System.Web.UI.Page
{
    ZSql rs = new ZSql();
    Function f = new Function();
    ZSql info = new ZSql();//添加修改
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           // lblName.Text = Server.UrlDecode(Request.Cookies["user"].Values["name"]);//操作人
            lblPatd.Text = f.getModuleidAdd(Request.QueryString["moduid"]);//当前位置
            hidModuid.Value = Request.QueryString["moduid"];
            HidGoUrl.Value = Request.UrlReferrer.ToString();
           
            if (!string.IsNullOrEmpty(Request["id"]))//初使化信息
            {
                initData();
            }
        }
    }
    private void initData()//当修改时,初使化数据
    {
        ZSql zs = new ZSql();
        string sql = "SELECT * FROM (SELECT stockId, ComodBarcode,Content,typeStock, ProcNum, ProcMoney, SuppliMoney, newSuppliMoney,ChainMoney,WholeMoney1,WholeMoney2,Prices,RetailMoney,RestMoney,ActiveMoney,EditUserName,EditDate, CONVERT(char(10), storageTime, 120) AS storageTime, AuditState, (SELECT WarehouseName FROM CS_Warehouse   WHERE WarehouseId = a.WarehouseId) AS WarehouseName, (SELECT Supplier FROM CS_Supplier WHERE SupplierId = a.SupplierId) AS SupplierName, (SELECT Brand  FROM Brand WHERE BrandId = a.BrandId) AS BrandName, (SELECT ComoditiesName FROM ComoditiesName  WHERE ComoditiesNameId = a.ComoditiesName) AS ComoditiesName, (SELECT Specifications FROM Specifications    WHERE SpecificationsId = a.ModelId) AS SpecificationsName, (SELECT Units FROM Units  WHERE UnitsId = a.UnitId) AS UnitsName, (SELECT ComoditiesType   FROM ComoditiesType    WHERE TypeId = a.ComoditiesType) AS ComoditiesTypeName FROM CS_Stock a ) Stock where stockId=" + Request.QueryString["id"] + " ORDER BY stockId DESC";
        zs.Open(sql);
            lblComodBarcode.Text = zs.m_table.Rows[0]["ComodBarcode"].ToString();
            lblProcNum.Text = zs.m_table.Rows[0]["ProcNum"].ToString();
            lblComoditiesTypeName.Text = zs.m_table.Rows[0]["ComoditiesTypeName"].ToString();
            LblSupplierName.Text = zs.m_table.Rows[0]["SupplierName"].ToString();
            LblBrandName.Text = zs.m_table.Rows[0]["BrandName"].ToString();
            lblComoditiesName.Text = zs.m_table.Rows[0]["ComoditiesName"].ToString();
            lblWarehouseName.Text = zs.m_table.Rows[0]["WarehouseName"].ToString();
            lblUnitsName.Text = zs.m_table.Rows[0]["UnitsName"].ToString();
            lblComoditiesName.Text = zs.m_table.Rows[0]["ComoditiesName"].ToString();
            LblSpecificationsName.Text = zs.m_table.Rows[0]["SpecificationsName"].ToString();
            lbltypeStock.Text = zs.m_table.Rows[0]["typeStock"].ToString();
            lblstorageTime.Text = zs.m_table.Rows[0]["storageTime"].ToString();
            lblContent.Text = zs.m_table.Rows[0]["Content"].ToString();
            lblName.Text = zs.m_table.Rows[0]["EditUserName"].ToString();
            lblDate.Text = zs.m_table.Rows[0]["EditDate"].ToString();
        //价格
            txtProcMoney.Text = zs.m_table.Rows[0]["ProcMoney"].ToString();
            txtSuppliMoney.Text = zs.m_table.Rows[0]["SuppliMoney"].ToString();
            txtnewSuppliMoney.Text = zs.m_table.Rows[0]["newSuppliMoney"].ToString();
            txtRetailMoney.Text = zs.m_table.Rows[0]["RetailMoney"].ToString();
            txtWholeMoney1.Text = zs.m_table.Rows[0]["WholeMoney1"].ToString();
            //txtWholeMoney2.Text = zs.m_table.Rows[0]["WholeMoney2"].ToString();
            txtRestMoney.Text = zs.m_table.Rows[0]["RestMoney"].ToString();
            txtChainMoney.Text = zs.m_table.Rows[0]["ChainMoney"].ToString();
            txtPrices.Text = zs.m_table.Rows[0]["Prices"].ToString();
            txtActiveMoney.Text = zs.m_table.Rows[0]["ActiveMoney"].ToString();
        zs.Close();
    }

    protected void btnAdd_Click(object sender, EventArgs e)//系统提交保存设置价格
    {
        string action = Request["action"];
        string sql="";
        if(isFlag.Checked)
            sql = "select top 1 * from CS_Stock where ComodBarcode='" + lblComodBarcode.Text.Trim()+"'";
        else
            sql = "select top 1 * from CS_Stock where stockId=" + Request.QueryString["id"];

        info.Open(sql);
            info.NextRow();
            info["ProcMoney"] = txtProcMoney.Text;
            info["SuppliMoney"] = txtSuppliMoney.Text;
            info["newSuppliMoney"] = txtnewSuppliMoney.Text;
            info["RetailMoney"] = txtRetailMoney.Text;
            info["WholeMoney1"] = txtWholeMoney1.Text;
            //info["WholeMoney2"] = txtWholeMoney2.Text;
            info["RestMoney"] = txtRestMoney.Text;
            info["ChainMoney"] = txtChainMoney.Text;
            info["Prices"] = txtPrices.Text;
            info["ActiveMoney"] = txtActiveMoney.Text;


        info.Update();
        info.Close();
        Response.Write("<script>alert('操作已成功，请返回！');</script>");//返回页面
        Response.Write("<script>window.location='" + HidGoUrl.Value + "';</script>");//返回页面

    }
}
